//
//  content.m
//  mainpage
//
//  Created by Anthony Zhang on 2018/7/23.
//  Copyright © 2018年 John Zheng. All rights reserved.
//

#import "content.h"
#import "contentModel.h"

@interface content ()<UITextViewDelegate>

@property (nonatomic,weak) UIImageView* user_headview;
@property (nonatomic,weak) UILabel* user_name;
@property (nonatomic,weak) UITextView* essay;
@property (nonatomic,weak) UIButton* thumbs_up;
@property (nonatomic,weak) UIButton* attention;

@end

@implementation content

- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        
        self.backgroundColor = [UIColor whiteColor];
        UIImageView *user_headview = [[UIImageView alloc]init];
        self.user_headview = user_headview;
        
        UILabel* user_name = [[UILabel alloc]init];
        user_name.textAlignment = NSTextAlignmentLeft;
        user_name.font = [UIFont systemFontOfSize:25];
        self.user_name = user_name;
        
        UITextView* essay = [[UITextView alloc]init];
        essay.layer.borderColor = [[UIColor blackColor]CGColor];
        essay.layer.borderWidth = 1;
        essay.backgroundColor = [UIColor clearColor];
        essay.font = [UIFont systemFontOfSize:20];
        essay.delegate = self;
        essay.editable = NO;
        self.essay = essay;
        
        UIButton* thumbs_up = [UIButton buttonWithType:UIButtonTypeCustom];
        [thumbs_up setImage:[UIImage imageNamed:@"thumbs_up1"] forState:UIControlStateNormal];
        [thumbs_up setImage:[UIImage imageNamed:@"thumbs_up2"] forState:UIControlStateSelected];
        [thumbs_up addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
        self.thumbs_up = thumbs_up;
        
        UIButton* attention = [UIButton buttonWithType:UIButtonTypeCustom];
        [attention setBackgroundColor:[UIColor lightGrayColor]];
        [attention setTitle:@"关 注" forState:UIControlStateNormal];
        [attention setTitle:@"已关注" forState:UIControlStateSelected];
        [attention addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
        self.attention = attention;
        
        [self addSubview:user_headview];
        [self addSubview:user_name];
        [self addSubview:essay];
        [self addSubview:thumbs_up];
        [self addSubview:attention];
    }
    return self;
}

- (void)buttonClick:(UIButton *)button {
    button.selected = !button.selected;
}

- (void)layoutSubviews {
    [super layoutSubviews];
    self.user_headview.frame = CGRectMake(10, 10, 50, 50);
    self.user_name.frame = CGRectMake(70, 15, 80, 40);
    self.essay.frame = CGRectMake(10, 70, self.bounds.size.width-20, self.bounds.size.height-150);
    self.thumbs_up.frame = CGRectMake(self.bounds.size.width-60, self.bounds.size.height-60, 50, 50);
    self.attention.frame = CGRectMake(self.bounds.size.width-90, 15, 80, 40);
    
}

- (void)setModel:(contentModel *)model {
    _model = model;
    self.user_headview.image = [UIImage imageNamed:model.headview];
    self.user_name.text = model.name;
    self.essay.text = model.essay;
}
@end
